package com.njitzx.service.impl;

import com.njitzx.entity.po.OperLog;
import com.njitzx.mapper.OperLogMapper;
import com.njitzx.service.OperLogService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java.io.Serializable;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


/**
 * <p>
 * 系统操作日志 服务实现类
 * </p>
 *
 * @author 周鑫
 * @since 2024-08-20
 */
@Service
@RequiredArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class OperLogServiceImpl implements OperLogService {

    private final OperLogMapper operLogMapper;

    /**
     * 系统操作日志分页查询
     * @param pageNum
     * @param pageSize
     * @param operLog
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public PageInfo<OperLog> findPage(Integer pageNum, Integer pageSize, OperLog operLog) {
        PageHelper.startPage(pageNum,pageSize);
        List<OperLog> operLogList = operLogMapper.select(operLog);
        return new PageInfo<>(operLogList);
    }

    /**
     * 根据主键查询系统操作日志
     * @param operId
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public OperLog findById(Serializable operId) {
        return operLogMapper.selectById(operId);
    }

    /**
     * 系统操作日志新增
     * @param operLog
     */
    @Async
    @Override
    public void add(OperLog operLog) {
        operLogMapper.insert(operLog);
    }

    /**
     * 修改系统操作日志
     * @param operLog
     */
    @Override
    public void modify(OperLog operLog) {
        operLogMapper.update(operLog);
    }

    /**
     * 根据主键删除系统操作日志
     * @param operId
     */
    @Override
    public void removeById(Serializable operId) {
        if(((String)operId).contains(",")){
            operLogMapper.deleteByIds(((String)operId).split(","));
        }else {
            operLogMapper.deleteById(operId);
        }
    }
}
